/*
 * One example for NOI CSP-J Lesson 8:
 * <https://courses.fmsoft.cn/plzs/noijunior-other-data-structures.html>
 *
 * Author: Vincent Wei
 *  - <https://github.com/VincentWei>
 *  - <https://gitee.com/vincentwei7>
 *
 * Copyright (C) 2025 FMSoft <https://www.fmsoft.cn>.
 * License: GPLv3
 */
#include <iostream>           // for std::cout
#include <cassert>            // for assert()

using namespace std;

#define MAX_N       20

uintmax_t factorial(unsigned n)
{
    static uintmax_t factorial_memoization[MAX_N + 1];

    assert(n <= MAX_N);

    if (n == 0)
        return 1;

    if (factorial_memoization[n - 1] == 0)
        factorial_memoization[n - 1] = factorial(n - 1);
    return n * factorial_memoization[n - 1];
}

int main()
{
    for (unsigned u = 0; u <= MAX_N; u++) {
        cout << u << ": " << factorial(u) << endl;
    }

    return 0;
}

